package com.cskaoyan.market.shiro;

import com.cskaoyan.market.service.WxAuthService;
import com.cskaoyan.market.service.WxUserService;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class JdbcRealm extends AuthorizingRealm {

    @Autowired
    WxAuthService authService;


    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        //传递过来的参数token其实就是在登录的时候，我们构建的token
        UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;
        String username = usernamePasswordToken.getUsername();
        //根据username查询对应的数据库中存储的密码
        String password = authService.queryPasswordByUsername(username);
        return new SimpleAuthenticationInfo(username, password, getName());
    }


    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        return null;
    }


}
